/*自定义轮播*/
//通过carousel函数操作选中的轮播器的轮播

$(document).ready(function() {
	//选中。carousel对应的轮播器，调用carousel()函数启动轮播
	//在大括号里给出一些参数，interval：3000间隔为3000毫秒
	$(".carousel").carousel({
		interval: 2500
	});
});

//鼠标悬浮事件
$(document).ready(function() {
	$(".nav>li").mouseenter(function() {
		$(this).children("a").dropdown("toggle");
	});
	//鼠标移除事件
	$(".nav>li").mouseleave(function() {
		$(this).children("a").dropdown("toggle");
	});
});

/*验证用户登录帐号*/
 function validateUser() {
 	/*获取输入框的帐号*/
 	var user = document.getElementById("user").value;
 	var userSapn =document.getElementById("userSpan");
 	if(user == "") {
 		userSapn.innerHTML = "用户帐号不能为空";
 		return;
 	}
 	var reg =/^[A-Z\a-z][A-Z\a-z\d\_]{5,15}$/;
 	if(!reg.test(user)) {
 		userSapn.innerHTML = "6-15位字符，字母开头，只包含字母数字下划线";
 		return;
 	}
 	userSapn.innerHTML = "";
 	 return true;
 }
/*验证用户登录密码*/
 function validatePwd() {
 		/*获取输入框的密码*/
       var pwd = document.getElementById("pwd").value;
       var pwdSapn = document.getElementById("pweSpan");
       if (pwd == "") {
       	pwdSapn.innerHTML = "密码不能为空";
 		return;
       }
       var reg =/^(?![^a-zA-Z]+$)(?!\D+$)/;
       if(!reg.test(pwd)) {
       		pwdSapn.innerHTML = "密码必须包含数字和字母";
       		return;
       }
       if(pwd.length < 8 && pwd.length != 0) {
       	pwdSapn.innerHTML = "密码不 能少于8位";
       		return;
       }
       pwdSapn.innerHTML = "";
       return true;  
 }
 
//登录事件
function register() {
	if(validateUser() && validatePwd()) {
		 document.getElementById("register").setAttribute("data-dismiss", "modal");
		alert("登录成功");
		
	}
}
//验证注册用户框
function validateEnrollUser() {
	 	/*获取输入框的帐号*/
 	var user = document.getElementById("enrollUser").value;
 	var userSapn =document.getElementById("enrollUserSpan");
 	if(user == "") {
 		userSapn.innerHTML = "注册用户帐号不能为空";
 		return;
 	}
 	var reg =/^[A-Z\a-z][A-Z\a-z\d\_]{5,15}$/;
 	if(!reg.test(user)) {
 		userSapn.innerHTML = "注册用户必须6-15位字符，字母开头，只包含字母数字下划线";
 		return;
 	}
 	userSapn.innerHTML = "";
 	 return true;
}
//验证注册密码输入框
function validateEnrollPwd() {
	   var pwd = document.getElementById("enrollPwd").value;
       var pwdSapn = document.getElementById("enrollPwdSpan");
       if (pwd == "") {
       	pwdSapn.innerHTML = "密码不能为空";
 		return;
       }
       var reg =/^(?![^a-zA-Z]+$)(?!\D+$)/;
       if(!reg.test(pwd)) {
       		pwdSapn.innerHTML = "密码必须包含数字和字母";
       		return;
       }
       if(pwd.length < 8 && pwd.length != 0) {
       	pwdSapn.innerHTML = "密码不 能少于8位";
       		return;
       }
       pwdSapn.innerHTML = "";
       return true;  
}
//验证确认密码输入框
function confirmEnrollPwd() {
	//获取注册密码框内容
	 var pwd = document.getElementById("enrollPwd").value;
	 //确认密码Span 
	 var pwdSapn = document.getElementById("confirmPwdSpan");
	 //获取确认密码框内容
	  var confirmPwd = document.getElementById("confirmPwd").value;
	  if(!(pwd === confirmPwd)) {
	  		pwdSapn.innerHTML = "俩次输入密码不一致";
 		    return;
	  }
	 pwdSapn.innerHTML = "";
       return true; 
}
//注册事件
function login() {
	if(validateEnrollUser() && validateEnrollPwd() &&confirmEnrollPwd()) {
		document.getElementById("enroll").setAttribute("data-dismiss", "modal");
		alert("注册成功");	
	}
}